﻿using System;
using UniFramework.Event;
using UniFramework.Network;
using UniFramework.Singleton;
using UniFramework.Window;
using UnityEngine;
using YooAsset;
using Object = UnityEngine.Object;


public static class App
{
    /**@description 进入后台的时间 */
    private static DateTime? _enterBackgroundTime = null;

    public static void Init(GameObject root)
    {
        UniSingleton.Initialize();

        UniEvent.Initalize();

        UniWindow.Initalize(root);

        UniNetwork.Initalize();

        var assetHandle = YooAssets.LoadAssetSync<GameObject>("LoadUI");
        if (!assetHandle.IsDone) return;
        var desktop = GameObject.Find("UI");
        Object.Instantiate(assetHandle.AssetObject, desktop.transform);
    }

    public static void OnDestroy()
    {
        UniSingleton.Destroy();
        UniEvent.Destroy();
        UniWindow.Destroy();
        UniNetwork.Destroy();
    }


    public static void OnEnterBackground()
    {
        _enterBackgroundTime = System.DateTime.Now;
        Debug.Log($"[App] OnEnterBackground {_enterBackgroundTime}");
        // App.globalAudio.onEnterBackground();
        // App.serviceManager.onEnterBackground();
    }

    public static void OnEnterForgeground()
    {
        var now = System.DateTime.Now;
        var inBackgroundTime = now - _enterBackgroundTime;
        Debug.Log($"[App] OnEnterForgeground {now} background total time : ${inBackgroundTime}");
        // App.globalAudio.onEnterForgeground(inBackgroundTime);
        // App.serviceManager.onEnterForgeground(inBackgroundTime);
    }
}